package com.iOS.service.impl;

import com.iOS.dao.UserInfoMapper;
import com.iOS.dto.BlogInfoExecution;
import com.iOS.entity.BlogInfo;
import com.iOS.dao.BlogInfoMapper;
import com.iOS.enums.BlogInfoEnum;
import com.iOS.service.IBlogInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class BlogInfoServiceImpl implements IBlogInfoService {
    @Autowired
    private BlogInfoMapper blogInfoMapper;

    @Override
    public BlogInfoExecution Add(BlogInfo blog) {
        try {
            BlogInfo blogInfo = new BlogInfo();
            blogInfo.setUserId(blog.getUserId());//用户名
            blogInfo.setBlogTitle(blog.getBlogTitle());
            blogInfo.setBlogContext(blog.getBlogContext());
            blogInfo.setBlogPictures(blog.getBlogPictures());
            blogInfo.setCreateTime(new Date());
            blogInfo.setUpdateTime(new Date());

            blogInfoMapper.insert(blogInfo);
            return new BlogInfoExecution(BlogInfoEnum.SUCCESS);
        } catch (Exception e) {
            return new BlogInfoExecution(BlogInfoEnum.FAIL);
        }
    }

    @Override
    public BlogInfoExecution Alter(BlogInfo blog) {
        try {
            BlogInfo blogInfo = new BlogInfo();
            blogInfo.setBlogTitle(blog.getBlogTitle());
            blogInfo.setBlogContext(blog.getBlogContext());
            blogInfo.setBlogPictures(blog.getBlogPictures());;
            blogInfo.setUpdateTime(new Date());
            blogInfoMapper.alter(blogInfo);
            return new BlogInfoExecution(BlogInfoEnum.SUCCESS);
        } catch (Exception e) {
            return new BlogInfoExecution(BlogInfoEnum.FAIL);
        }
    }
    
    
    @Override
    public  List<BlogInfo> getBlogList(){
    return   blogInfoMapper.queryAll();
    }


    @Override
    public   BlogInfo getById(int id){
        return  blogInfoMapper.queryById(id);
    }


    @Override
    public void Delete(int id) {
        blogInfoMapper.delete(id);

    }


}
